IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'spProducts_RetrieveAll')
	BEGIN
		PRINT 'Dropping Procedure spProducts_RetrieveAll'
		DROP  Procedure  spProducts_RetrieveAll
	END

GO

PRINT 'Creating Procedure spProducts_RetrieveAll'
GO

CREATE Procedure spProducts_RetrieveAll
	(
		@ProductName varchar(50) = null, 
		@DivisionName varchar(50) = null, 
		@DepartmentName varchar(50) = null
	)
AS
    /* 
    ------------------------------------------------------------------------------
    - Change History
    - --------------
    - Date          Description
    ------------------------------------------------------------------------------
    - 2007/11/02	Initial version created
    ------------------------------------------------------------------------------
    */
	
	SET NOCOUNT ON
	
	-- Retrieve the relevant records
	SELECT  *
	FROM	Products
	
	WHERE	(@ProductName IS NULL OR Products.ProductName LIKE @ProductName + '%')
	  AND	(@DivisionName IS NULL OR Products.DivisionName LIKE @DivisionName + '%')
	  AND	(@DepartmentName IS NULL OR Products.DepartmentName LIKE @DepartmentName + '%')

	-- Return to calling method
	RETURN
GO
